package inits

import (
	"developer-branch/glodal"
	"developer-branch/internal/model"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func MysqlConfig() {
	var err error
	dsn := fmt.Sprintf("root:root@tcp(127.0.0.1:3306)/2210y?charset=utf8mb4&parseTime=True&loc=Local")
	glodal.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("数据库连接失败")
		return
	}
	fmt.Println("数据库连接成功")
	err = glodal.DB.AutoMigrate(&model.User{}, model.Room{}, &model.RoomUser{}, &model.ChatHistory{})
	if err != nil {
		fmt.Println("数据迁移失败")
		return
	}
	fmt.Println("数据迁移成功")
}
